from urllib.request import urlopen, Request

if __name__ == '__main__':
    url = "https://www.baidu.com/"
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"
    }
    req = Request(url=url,headers=headers )
    response = urlopen(req)

    # 获取响应状态码
    print(response.getcode())

    # 读取网页内容，并进行解码
    content = response.read().decode("utf-8")
    print(content)

